package com.project.controller;

import com.project.dto.StockTransactionQueryDTO;
import com.project.result.PageResult;
import com.project.result.Result;
import com.project.service.StockTransactionsService;
import com.project.vo.StockTransactionListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 库存流水
 */
@RestController
@RequestMapping("/stockTransactions")
@Slf4j
public class StockTransactionsController {

    @Autowired
    private StockTransactionsService stockTransactionsService;

    /**
     * 分页查询库存列表
     *
     * @return
     */
    @GetMapping
    public Result queryStockTransactionPage(StockTransactionQueryDTO stockDto) {
        PageResult<StockTransactionListVO> pageResult = stockTransactionsService.queryStockTransactionPage(stockDto);
        return Result.success(pageResult);
    }

    /**
     * 根据流水ID查询详细的出入库流水信息
     * @param id 流水ID
     * @return
     */
    @GetMapping("/{id}")
    public Result<StockTransactionListVO> getById(@PathVariable Integer id) {
        StockTransactionListVO stockTransactionListVO = stockTransactionsService.getStockTransactionById(id);
        return Result.success(stockTransactionListVO);
    }

    /**
     * 删除库存流水
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteStockTransaction(@PathVariable Integer id) {
        boolean result = stockTransactionsService.removeById(id);
        return result ? Result.success() : Result.error("删除失败");
    }

}
